package com.by.course.config.web.jwt;


import com.by.course.entity.bo.UserToken;

/**
 *
 * @author zhd
 * @date 2023/09/11 13:22
 **/
public class UserUtil {

    private static final ThreadLocal<UserToken> currentUsers = new ThreadLocal<>();

    public static void setUser(UserToken userDO) {
        currentUsers.set(userDO);
    }

    public static void remove() {
        currentUsers.remove();
    }

    public static UserToken getUser() {
        return  currentUsers.get();
    }

    public static Long getUserId() {
        UserToken userDO = currentUsers.get();
        if (userDO != null) {
            return userDO.getUserId();
        }
        return null;
    }
}
